﻿@{
    ViewBag.Title = "";
}
<script type="text/javascript">
    //树
    var zNodes_Permission_Organize_SelectOrganize = [];
    var clickState_Permission_Organize_SelectOrganize = false; //标识是否选择了节点
    var zTree1_Permission_Organize_SelectOrganize;
    var setting_Permission_Organize_SelectOrganize;
    var tempID = 0; //记录选中节点的id
    var tempName = ""; //记录选中节点名称
    var FromOrg_Permission_Organize_SelectOrganize = 0; //1代表该节点来自组织机构，2代表来自岗位
    setting_Permission_Organize_SelectOrganize = {
        checkable: false,
        async: true,
        isSimpleData: true,
        asyncUrl: "/Permission/Organize/GetOrganizeNodes/@ViewBag.TempFlag",  //获取节点数据的URL地址
        //asyncDataFilter: ajaxDataFilter,
        nameCol: "Name",
        open: false,
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_Permission_Organize_SelectOrganize,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_Permission_Organize_SelectOrganize
        }
    };

    function zTreeOnAsyncSuccess_Permission_Organize_SelectOrganize(event, treeId, treeNode, msg) {
        //异步成功
    }

    //树的单击事件
    function zTreeOnClick_Permission_Organize_SelectOrganize(event, treeId, treeNode) {
        tempID = treeNode.Id.substring(2, treeNode.Id.length);
        tempName = treeNode.Name;
        clickState_Permission_Organize_SelectOrganize = true;
        if (treeNode.Id.substring(0, 2) == "C_")
            FromOrg_Permission_Organize_SelectOrganize = 1;
        else if (treeNode.Id.substring(0, 2) == "D_")
            FromOrg_Permission_Organize_SelectOrganize = 2;
        //alert(tempID + "---->" + tempName + "----->" + FromOrg_Permission_Organize_SelectOrganize);
    }

    $(document).ready(function () {
        refreshTree_Permission_Organize_SelectOrganize("/Permission/Organize/GetOrganizeNodes/@ViewBag.TempFlag");

    });
    function refreshTree_Permission_Organize_SelectOrganize(asyncUrl) {
        $("#getUrl").html("");
        $("#onAsyncSuccessNode").html("<br/>");
        $("#onAsyncErrorNode").html("<br/>");
        setting_Permission_Organize_SelectOrganize.asyncUrl = asyncUrl;
        if ((typeof asyncUrl) == "function") {
            $("#asyncUrlCode").html("setAsyncUrl");
        } else {
            $("#asyncUrlCode").html("\"" + asyncUrl + "\"");
        }
        zTree1_Permission_Organize_SelectOrganize = $("#tree_Permission_Organize_SelectOrganize").zTree(setting_Permission_Organize_SelectOrganize, zNodes_Permission_Organize_SelectOrganize);
    }
    $("#btnSave_Permission_Organize_SelectOrganize").click(function () {
        if (!clickState_Permission_Organize_SelectOrganize) {//如果没有选择节点就不能点击确定按钮
            alertMsg.error("请选择节点！");
            return false;
        }
        var selectedNode = zTree1_Permission_Organize_SelectOrganize.getSelectedNode();
        //alert(tempID + "---->" + tempName + "----->" + FromOrg_Permission_Organize_SelectOrganize);
        if (tempID != (FromOrg_Permission_Organize_SelectOrganize == 1 ? $("#Id").val() : $("#ID").val())) {
            if ("@ViewBag.Flag" == "1") {
                $("#ParentId").val(tempID);
                $("#txtParentName").val(tempName);
            } else if ("@ViewBag.Flag" == "2") {
                $("#OrganizeId").val(tempID);
                $("#txtDepartmentName").val(tempName);
            } else if ("@ViewBag.Flag" == "3") {//在添加职员页面选定公司
                $("#CompanyId").val(tempID);
                $("#txtCompanyName").val(tempName);
            } else if ("@ViewBag.Flag" == "4") {//在添加职员页面选定部门
                $("#DepartmentId").val(tempID);
                $("#txtDepartmentName").val(tempName);
            } else if ("@ViewBag.Flag" == "5") {//在添加职员页面选定岗位
                $("#DutyId").val(tempID);
                $("#txtDutyName").val(tempName);
            } else if ("@ViewBag.Flag" == "6") {//在添加职员页面选定工作组
                $("#WorkgroupId").val(tempID);
                $("#txtWorkgroupName").val(tempName);
            } else if ("@ViewBag.Flag" == 7) {//添加现有职员
                if (selectedNode.Mark != "Staff") {
                    return false;
                }
                //职员岗位挂接
                var parentId_SelectOrganize = $("#parentId_permission_Organize_SelectOrganize").val();
                $.post("/Permission/Organize/CreateConnectionDutyAndStaff", { dutyId: parentId_SelectOrganize.substring(0, parentId_SelectOrganize.indexOf('_')), staffId: selectedNode.Id, orgId: parentId_SelectOrganize.substring(parentId_SelectOrganize.indexOf('_') + 1, parentId_SelectOrganize.length) }, CreatStaffAdded_Permission_Organize, "json");
            }
            $.pdialog.closeCurrent();
        } else
            alertMsg.error("父节点选择有误，请重新选择！");
    });
</script>
<div class="pageContentD">
    <div class="pageFormContent" layouth="60">
        <ul id="tree_Permission_Organize_SelectOrganize" class="ztree">
        </ul>
        <input type="hidden" id="parentId_permission_Organize_SelectOrganize" value="@ViewBag.ReceiveId" />
    </div>
    <div class='formBar'>
        <ul>
            <li>
                <button type="button" class="btn btn-success btn-sm" id="btnSave_Permission_Organize_SelectOrganize">
                    确定</button>
            </li>
            <li>
                <button type="button" class="close btn btn-default btn-sm">
                    取消</button>
            </li>
        </ul>
    </div>
</div>
